﻿CREATE PROCEDURE dbo.sp_Insert_Account
	(
		@AccountID VARCHAR(10),
		@FirstName VARCHAR(50),
		@LastName VARCHAR(50),
		@Password VARCHAR(50),
		@Email VARCHAR(100),
		@AccountType INT,
		@DivsionNum varchar(2)
	)
AS
	SET NOCOUNT ON

	BEGIN TRAN T1

	INSERT INTO Accounts (AccountID, FirstName, LastName, Password, Email, AccountType, DivisionNum, IsRuleEnabled, IsRepeatRuleEnabled) 
	VALUES (@AccountID, @FirstName, @LastName, @Password, @Email, @AccountType, @DivsionNum, 1, 1);
	
	INSERT INTO [dbo].[PasswordHistory]
           ([AccountID]
           ,[PasswordP1]
           ,[P1Date])
     VALUES
           (@AccountID
           ,@Password
           ,GETDATE())
           
	IF ( @@ERROR <> 0 )
	BEGIN
		ROLLBACK TRAN T1
	END

	COMMIT TRAN T1
	
	
	